﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bai1_So_Nguyen_To_
{
    class Program
    {
        static public void Nhapday(int []a, ref int n)
        {
            string s;
            nhap1:
            try
            {
                Console.Write("Nhap vao so luong phan tu cua day : ");
                s = Console.ReadLine();
                n = int.Parse(s);
            }
            catch
            {
                Console.WriteLine("Loi ve nhap du lieu!!!");
                goto nhap1;
            }
            while (n <= 0 && n > 100)
            {
                Console.Write("Moi ban nhap lai so phan tu cua day : ");
                s = Console.ReadLine();
                n = int.Parse(s);
            }
            for(int i=0; i<n; i++)
            {
            nhap2:
                try
                {
                    Console.Write("Nhap a[{0}] : ", i.ToString());
                    s = Console.ReadLine();
                    a[i] = int.Parse(s);
                }
                catch
                {
                    Console.WriteLine("Loi ve nhap du lieu.Ban can nhap lai!!!");
                    goto nhap2;
                }

            }
        }
        static public void Xuatday(int[] a, int n)
        {
            string s;
            Console.WriteLine("Day so moi nhap vao la : ");
            for (int i=0; i<n; i++)
            {
                s=a[i].ToString();
                Console.Write(s);
                Console.Write("    ");
            }
            Console.ReadLine();
        }
        static public void SoNT(int[] a, int[] b, int n, ref int m)
        {
            string s;

            int dem = 0;
            
            for (int i = 0; i < n; i ++)
            {
                bool k= true ;
                if (a[i] == 2 || a[i] == 3)
                {
                    k = true;
                   // break;
                }
                else if (a[i] == 1)
                {
                    k = false;
                    //break;
                }
                else
                {

                    for (int j = 2; j <= a[i] - 1; j++)


                        if (a[i] % j == 0)
                        {
                            k = false;
                            break;

                        }


                }
                if (k == true)
                {
                    b[dem] = a[i];
                    dem++;
                   
                }
            }
            m = dem;
            if (m == 0)
            {
                Console.WriteLine("Khong co so nguyen to nao trong day so da nhap!!!");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Nhung so nguyen to co trong day vua nhap la : ");
                for (int j = 0; j < m; j++)
                {
                    s = b[j].ToString();
                    Console.Write(s);
                    Console.Write("    ");
                }
                Console.ReadLine();

               //Array.Sort(b);
                Console.WriteLine("So nguyen to lon nhat trong day la : ");
                int max = b[0];
                for (int i = 1; i < m; i++)
                    if (b[i] > max)
                        max = b[i];
                    Console.Write(max);
                Console.ReadLine();
            }

            
        }
        static void Main(string[] args)
        {
            int n = 0;
            int m = 0;
                    
            int[] a = new int[100];
            int[] b = new int[100];
            //songuyento:
            Nhapday(a, ref n);
            Xuatday(a, n);
            SoNT(a, b, n, ref m);
            //goto songuyento;
        }
    }
}
